App({
  async onLaunch() {
    this.initcloud()

    this.globalData = {
      //记录使用者的openid
      _openidA: 'oVZEY5L-kzoMOTC4tJKH04o4hOyQ',
      _openidB: 'oVZEY5OhyCbkRV7YkQLAmnEDCzEM',

      //记录使用者的名字
      userA: '阿拉长',
      userB: '诺伯德',

      idToUser: {'oVZEY5L-kzoMOTC4tJKH04o4hOyQ': '阿拉长', 'oVZEY5OhyCbkRV7YkQLAmnEDCzEM': '诺伯德',},
      userToId: {'阿拉长': 'oVZEY5L-kzoMOTC4tJKH04o4hOyQ', '诺伯德': 'oVZEY5OhyCbkRV7YkQLAmnEDCzEM',},

      //用于存储待办记录的集合名称
      collectionMissionList: 'MissionList',
      collectionMarketList: 'MarketList',
      collectionStorageList: 'StorageList',
      collectionUserList: 'UserList',
      collectionExecutedRecordList: 'ExecutedRecordList',
      "images": {
        "MainPage": ["cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/images/摩天轮1.jpg", "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/images/摩天轮2.jpg", "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/images/避雨.jpg", "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/images/休憩.jpg"],
        "Account": {"None": "Images/None.png", "Star": "Images/Star.png"},
        "Market": {
          "MarketA": "Images/MarketA.png", "MarketB": "Images/MarketB.png",
          "MarketCover": "Images/MarketCover.jpg", 
          "MarketCover01": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/images/工作.jpg",
          "MarketCover02": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/images/游戏.jpg",
          "MarketCover03": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/images/冲浪.jpg", 
          "MarketCover04": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/images/逛街.jpg",
          "MarketCover05": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/images/睡觉.jpg",
          "None": "Images/None.png", "Plus": "Images/Plus.png",
          "Star": "Images/Star.png",
        },
        "Mission": {
          "MissionA": "Images/MissionA.png", "MissionB": "Images/MissionB.png",
          "MissionCover01": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/images/油炸.jpg",
          "MissionCover02": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/images/早餐.jpg", 
          "MissionCover03": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/images/干饭.jpg",
          "MissionCover04": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/images/干饭2.jpg",
          "MissionCover05": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/images/看雪.jpg",
          "None": "Images/None.png",
          "Plus": "Images/Plus.png", "Star": "Images/Star.png",
        }
      },
      "gifs": {
        "ItemDetail": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/Item.gif",
        "MarketAdd": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/Item.gif",
        "MarketDetail": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/Item.gif",
        "MissionAdd": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/Mission.gif",
        "MissionDetail": "cloud://database-6gl5uwim0325fc4a.6461-database-6gl5uwim0325fc4a-1313304083/Mission.gif"
      },
      //最多单次交易积分
      maxCredit: 2000,
    }
  },

  flag: false,

  /**
   * 初始化云开发环境
   */
  async initcloud() {
    const normalinfo = require('./envList.js').envList || [] // 读取 envlist 文件
    if (normalinfo.length != 0 && normalinfo[0].envId != null) { // 如果文件中 envlist 存在
      wx.cloud.init({ // 初始化云开发环境
        traceUser: true,
        env: normalinfo[0].envId
      })
      // 装载云函数操作对象返回方法
      this.cloud = () => {
        return wx.cloud // 直接返回 wx.cloud
      }
    } else { // 如果文件中 envlist 不存在，提示要配置环境
      this.cloud = () => {
        wx.showModal({
          content: '无云开发环境', 
          showCancel: false
        })
        throw new Error('无云开发环境')
      }
    }
  },

  // 获取云数据库实例
  async database() {
    return (await this.cloud()).database()
  },

  //显示完成情况
  showFinishInfo(title, icon, duration){
    wx.showToast({
      title: title,
      icon: icon,
      duration: duration
    })
  },
})